<?php

namespace Console\Controller;

use Console\Common\Library\Page;
use Common\Controller\AdminAuthController;

class WithdrawalController extends CstBaseController
{
    private $withdrawalLogic;
    const TABLE_NAME="Withdrawal";

    public function _initialize()
    {
        parent::_initialize();
        $this->withdrawalLogic = A('Console/Withdrawal', 'Logic');
    }

    public function withdrawalList()
    {
        $typeDic = $this->withdrawalLogic->getTypeDic();
        $this->assign("typeDic", $typeDic);
        $this->display();
    }

    /**
     * 获取提现列表
     *
     * @return void
     */
    public function doGetList()
    {
        $data = I('post.');
        $page = $data['page'] ? $data['page'] : 1;
        $pageSize = 15;
        unset($data['page']);

        $listRes = $this->withdrawalLogic->getList($page, $pageSize, $data);
        $data = $listRes['Result'];
        $total = $data['total'];
        $list = $data['list'];

        $PageLib = new Page($total, $pageSize);
        $pageHtml = $PageLib->show();
        $pageTotal = ceil($total / $pageSize);

        $typeDic = $this->withdrawalLogic->getTypeDic();

        $this->assign("typeDic", $typeDic);
        $this->assign("total", $total);
        $this->assign("pageTotal", $pageTotal);
        $this->assign("pageHtml", $pageHtml);
        $this->assign("list", $list);
        $this->assign("pageHtml", $pageHtml);
        $html = $this->fetch('doGetWithdrawalList');

        $res = array(
            "list" => $list,
            "html" => $html,
            "total" => $total,
            "pageTotal" => $pageTotal
        );
        $this->ajaxReturn(static::$res->suc("成功", $res));
    }

    


    /**
     * 审核通过取现申请
     *
     * @return void
     */
    public function doPassWithdrawal()
    {
        $id = I('post.id');
        $userInfo = $this->getUserInfo();
        $phone = $userInfo["phone"];
        $res = $this->withdrawalLogic->audit($phone, $id, 2);
        $this->ajaxReturn($res);
    }

    /**
     * 审核不通过取现申请
     *
     * @return void
     */
    public function doCancelWithdrawal()
    {
        $id = I('post.id');
        $msg = I("post.msg");
        $userInfo = $this->getUserInfo();
        $phone = $userInfo["phone"];
        $res = $this->withdrawalLogic->audit($phone, $id, 3, $msg);
        $this->ajaxReturn($res);
    }
}
